// page/component/orders/orders.js
Page({
  data:{
    address:{},
    hasAddress: false,
    total:0,
    orders:[
      { id: 1, busname: '盛亚福源自营旗舰店', title: '盛亚福源 牛肉黄金烤肠 500g', image: 'http://img.ehalfresh.com/ejsimage/images/seller/17/dcd34ae0-0e98-426a-9597-fad62b0b6435.jpg', num: 4, price: '24.50', Total: '200.00',},
      { id: 2, busname: '北大荒自营旗舰店', title: '鸡肉汉堡饼 250g ', image: 'http://img.ehalfresh.com/ejsimage/images/seller/17/f9cb6ffb-f104-45c3-8d1e-089a9c863d42.jpg', num: 1, price: ' 553.00', Total: '325.45',}
      ]
  },

  onReady() {
    this.getTotalPrice();
  },
  
  onShow:function(){
    const self = this;
    wx.getStorage({
      key:'address',
      success(res) {
        self.setData({
          address: res.data,
          hasAddress: true
        })
      }
    })
  },

  /**
   * 计算总价
   */
  getTotalPrice() {
    let orders = this.data.orders;
    let total = 0;
    for(let i = 0; i < orders.length; i++) {
      total += orders[i].num * orders[i].price;
    }
    this.setData({
      total: total
    })
  },

  toPay() {
    wx.showModal({
      title: '提示',
      content: '本系统只做演示，支付系统已屏蔽',
      complete() {
        wx.switchTab({
          url: '/page/component/user/user'
        })
      }
    })
  }
})